package function;

import java.util.ArrayList;

import data.Admin;

public class AdminManager {
	
	private final static ArrayList<Admin> adminList = new  ArrayList<Admin>();
	private static Admin currentAdmin = null;
	
	public static void init() {
		
	}
	
	public static void addAdmin(String username, String password) {
		Admin admin = new Admin(username, password);
		adminList.add(admin);
	}
	
	public static void loadAdmins(String[][] loadList) {
		for(String[] i:loadList) {
			Admin admin = new Admin(i[0], i[1]);
			adminList.add(admin);
		}
	}
	
	public static boolean verify(String username, String password) {
		for(Admin i:adminList) {
			if(i.getUserName().equals(username)) {
				if(i.getPassword().equals(password)) {
					setCurrentAdmin(i);
					return true;
				} else {
					return false;
				}
			}
		}
		return false;
	}

	public static Admin getCurrentAdmin() {
		return currentAdmin;
	}

	private static void setCurrentAdmin(Admin currentAdmin) {
		AdminManager.currentAdmin = currentAdmin;
	}
	
	public static void canclLogin() {
		setCurrentAdmin(null);
	}
}
